package org.example;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * Hello world!
 *
 */
@Slf4j
public class App 
{
    public static void main( String[] args ) throws IOException {
//        ByteBuffer buffer = ByteBuffer.allocate(28);
////        ByteBuffer.allocateDirect()
//        buffer.put("Hello World\nI am zhangsan\nHe".getBytes());
//        split(buffer);
//        buffer.put("llo zhangsan\nI am lisi\n".getBytes());
//        split(buffer);

//        Path source = Paths.get("test.txt");
//        System.out.println(source);
//        System.out.println(System.getProperty("user.dir"));
//        Files.copy(source, Paths.get("test2.txt"));
//        System.out.println(NettyRuntime.availableProcessors());


          StringBuilder s = new StringBuilder("Hello World");
          log.info("原始对象的内存地址：[{}]",System.identityHashCode(s));
          for(int i = 0; i < 10; i++){
              s.append("@");
              log.info("新对象的内存地址：[{}]",System.identityHashCode(s));
          }

          String ss = "Hello World";
          log.info("原始对象的内存地址：[{}]",System.identityHashCode(ss));
          for(int i = 0; i < 10; i++){
              ss += "@";
              log.info("新对象的内存地址：[{}]",System.identityHashCode(ss));
          }


//        System.out.println(new HelloClient());
    }
    private static void split(ByteBuffer buffer) {
        buffer.flip();
        for (int i = 0; i < buffer.limit(); i++){
            if(buffer.get(i)=='\n'){
                int length  = i+1 - buffer.position();
                ByteBuffer target = ByteBuffer.allocate(length);
                for (int i2 = 0; i2 < length; i2++){
                    target.put(buffer.get());
                }
                System.out.println(new String(target.array()));
            }
        }
        buffer.compact();
    }


}
